//
//  LMLocalPartnerInfo.m
//  LM
//
//  Created by Kien Tran on 2/4/13.
//  Copyright (c) 2013 Kien Tran. All rights reserved.
//

#import "LMLocalPartner.h"
#import "LMConstant.h"

@implementation LMLocalPartner
@synthesize ID = _ID, phone = _phone, facebook = _facebook, datingFirstDate = _datingFirstDate;



- (id)initWithName:(NSString *)name sex:(BOOL)isMale andBirthday:(NSDate *)birthday {
    self = [super initWithName:name sex:isMale andBirthday:birthday];
    
    if (self) {
        self.ID = -1;
    }
    
    return self;
}

- (id)initWithName:(NSString *)name sex:(BOOL)isMale birthday:(NSDate *)birthday phone:(NSString *) phone facebook:(NSString *) facebook datingFirstDate:(NSDate *) datingFirstDate {
    self = [super initWithName:name sex:isMale andBirthday:birthday];
    
    if (self) {
        self.ID = -1;
    
        self.phone = phone ? [phone copy] : phone;
        self.facebook = facebook ? [facebook copy] : facebook;
        self.datingFirstDate = datingFirstDate ? [datingFirstDate copy] : datingFirstDate;
    }
    
    return self;
}


- (id) copy {
    LMLocalPartner *copyingLocalUser = [[LMLocalPartner alloc] init];
    
    [copyingLocalUser setUserName:self.userName];
    [copyingLocalUser setSex:self.sex];
    [copyingLocalUser setBirthday:self.birthday];
    [copyingLocalUser setID:self.ID];
    [copyingLocalUser setPhone:self.phone];
    [copyingLocalUser setFacebook:self.facebook];
    [copyingLocalUser setDatingFirstDate:self.datingFirstDate];
    
    return copyingLocalUser;
}

- (void)copy:(LMLocalPartner *)sender {
    [super copy:sender];
    self.ID = sender.ID;
    self.datingFirstDate = sender.datingFirstDate;
    self.phone = sender.phone;
    self.facebook = sender.facebook;
}

- (NSDictionary *)dictionary {
    NSMutableDictionary *dic = (NSMutableDictionary *)[super dictionary];
    
    
    [dic setObject:[NSString stringWithFormat:@"%d",self.ID] forKey:@"ID"];
    
    if (self.phone) {
        [dic setObject: self.phone forKey:@"phone"];
    }
    
    if (self.facebook) {
        [dic setObject:self.facebook forKey:@"facebook"];
    }
    
    if (self.datingFirstDate) {
        [dic setObject:self.datingFirstDate forKey:@"dating_frist_date"];
    }
    
    return dic;
}

- (id)initWithDictionary:(NSDictionary *)dictionary {
    self = [super initWithDictionary:dictionary];
    if (self) {
        self.ID = [[dictionary objectForKey:@"ID"] integerValue];
        self.phone = [dictionary objectForKey:@"phone"];
        self.facebook = [dictionary objectForKey:@"facebook"];
        self.datingFirstDate = [dictionary objectForKey:@"dating_frist_date"];
    }
    return self;
}

- (NSString *) getDatingFirstDateString {
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    
    dateFormatter.dateFormat = kDATE_FORMAT;
    
    if (self.datingFirstDate) {
        return [dateFormatter stringFromDate:self.datingFirstDate];
    }
    
    return nil;
}

@end
